package com.app.controller.backstage;


import com.app.model.AdminUserModel;
import com.app.model.GraduationStatusModel;
import com.app.model.LivePortendModel;
import com.app.model.SchoolModel;
import com.app.service.*;

import com.app.util.CommonHelp;
import com.app.util.DateUtil;
import com.app.util.Result;
import com.app.util.TokenUtils;
import com.app.vo.GraduationStatusVo;
import com.app.vo.SchoolVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;


@RestController
@Controller
public class SchoolController {

    @Autowired
    private SchoolService schoolService;
    @Autowired
    AdminUserService adminUserService;
    @Autowired
    GraduationStatusService graduationStatusService;

    @GetMapping("bakGetSchoolList")//后台查学校列表
    public Result<Object> bakGetSchoolList(HttpServletRequest request,
                                      @RequestParam(required = false) String schoolName,
                                      int page,
                                      int limit) {

        SchoolModel model = new SchoolModel();
        model.setPage(page);
        model.setLimit(limit);
        model.setSchoolName(schoolName);
        SchoolVo vo = schoolService.bakGetSchoolList(model);
        return Result.success(vo);
    }

    @GetMapping("bakGetSchoolById")//后台查学校
    public Result<Object> bakGetSchoolById(HttpServletRequest request,
                                           @RequestParam(required = false) Integer id) {
        SchoolModel model = schoolService.getModelById(id);
        return Result.success(model);
    }

    /**
     * 编辑学校
     */
    @PostMapping("/editSchool")
    @ResponseBody
    public Result editSchool(HttpServletRequest request, SchoolModel model) {

        model.setCrtTime(CommonHelp.getNowTimestamp().toString());


        if(model.getId()!=null&&model.getId()>0)
        {
            schoolService.update(model);
        }else {
            schoolService.insert(model);
        }

        return Result.success("操作成功");
    }


    /**
     * 删除学校
     */
    @PostMapping("/deleteSchool")
    @ResponseBody
    public Result deleteSchool(HttpServletRequest request, Integer id) {

        schoolService.delete(id);
        return Result.success("操作成功");
    }

    @GetMapping("bakGetSpecialityList")//后台查学校专业列表
    public Result<Object> bakGetSpecialityList(HttpServletRequest request,
                                           @RequestParam(required = false) String speciality,
                                               @RequestParam(required = false) Integer schoolId,
                                           int page,
                                           int limit) {
        GraduationStatusModel model = new GraduationStatusModel();
        model.setSchoolId(schoolId);
        model.setPage(page);
        model.setLimit(limit);
        model.setSpeciality(speciality);
        GraduationStatusVo vo = graduationStatusService.bakGetModelList(model);
        return Result.success(vo);
    }

    @GetMapping("bakGetMajorById")//后台查专业
    public Result<Object> bakGetMajorById(HttpServletRequest request,
                                           @RequestParam(required = false) Integer id
    ) {

        GraduationStatusModel model = graduationStatusService.getModelById(id);
        return Result.success(model);
    }

    /**
     * 编辑专业
     */
    @PostMapping("/editMajor")
    @ResponseBody
    public Result editMajor(HttpServletRequest request, GraduationStatusModel model) {

        model.setCrtTime(CommonHelp.getNowTimestamp().toString());


        if(model.getId()!=null&&model.getId()>0)
        {
            graduationStatusService.update(model);
        }else {
            graduationStatusService.insert(model);
        }

        return Result.success("操作成功");
    }


    /**
     * 删除专业
     */
    @PostMapping("/deleteMajor")
    @ResponseBody
    public Result deleteMajor(HttpServletRequest request, Integer id) {

        graduationStatusService.delete(id);
        return Result.success("操作成功");
    }
}
